package edu.ynu.se.xiecheng.achitectureclass.service;

import edu.ynu.se.xiecheng.achitectureclass.common.service.LogicService;
import edu.ynu.se.xiecheng.achitectureclass.dao.UserDao;
import edu.ynu.se.xiecheng.achitectureclass.entity.Admin;
import edu.ynu.se.xiecheng.achitectureclass.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class UserService extends LogicService<UserDao,User,Long> {

    public UserService(@Autowired UserDao dao) {
        super(dao);
    }

    /**
     *  TODO
     * @param username
     * @param password
     * @return
     */
    public String login(String username, String password){
        return  null;
    }

    @Transactional
    public User findUser(String username){
        return dao.findByUsername(username);
    }
    @Transactional
    public void addDefaultUser(){
        if (dao.count() > 0) return;
        Admin admin = new Admin();
        admin.setUsername("admin");
        admin.setPassword("admin");
        dao.save(admin);
    }
}
